<?php

namespace Admin\Controller;
use Think\Controller;
class MyMemberController extends AdminController {
	// 会员查询操作
	public function userlist()
	{
		// 获取排序条件
    $content = null != (string)(I('request.sort')) ? (string)(I('request.sort')) : 'desc';
    $order['user_id'] = $content;
		
		$username       =   I('username');
    $map['status']  =   array('egt',0);
    if(is_numeric($username)){
        $map['user_id|username']=   array(intval($username),array('like','%'.$username.'%'),'_multi'=>true);
    }else{
        $map['username']    =   array('like', '%'.(string)$username.'%');
    }
		$list = $this->lists('user',$map,$order);
		// 修改状态
		$stat = ['禁用','启用'];
	     foreach($list as $key=>&$val){
	      	$val['status'] = $stat[$val['status']];
	      }
	     // 变量赋值
		$this->assign('list',$list);
		// 模板展示
		$this->display();
	}

	// 用户排序操作
	public function sort(){
		$user = new \Admin\Model\MyMemberModel('user');
		$list=$user->mysort();
		$stat = ['禁用','启用'];
	     foreach($list as $key=>&$val){
	      	$val['status'] = $stat[$val['status']];
	      }
		//  // 变量赋值
		$this->assign('list',$list);
		// 模板展示
		$this->display('userlist');
	}

	public function change(){
		$user_id=I('get.user_id');
		$user = new \Admin\Model\MyMemberModel('user');
		$list=$user->find($user_id);
		if($list['status']==1){
			$user->status = '0';
			$res = $user->where("user_id={$user_id}")->save();
			echo $res;
		}else{
			$user->status = '1';
			$res = $user->where("user_id={$user_id}")->save();
			echo $res;
		}
	}

}
